/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2025-03-04
 * Time: 20:47
 */
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            //System.out.println("t: " + Thread.currentThread().getName());
            while(!Thread.currentThread().isInterrupted()){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //1.加上break 就是立即终止
                    //2.什么都不加 就是不终止

                }
            }
            System.out.println("t 结束");
        });

        t.start();
        Thread.sleep(3000);
        System.out.println("main 线程尝试终止 t 线程");
        t.interrupt();
    }
}
